<template>
	<view class="content">
		<scroll-view scroll-x class="tabs-content" enable-flex scroll-with-animation>
			<view class="order-nav">
				<view class="nav-item" v-for="(nav, index) in orderState" :key="index" @tap="onNav(index, nav.id)">
					<view class="item-title" :class="{ 'item-title-active': tabindex === index }">{{ nav.title }}</view>
					<view class="nav-line" :class="{ 'line-active': tabindex === index }"></view>
				</view>
			</view>
		</scroll-view>
		<mescroll-body ref="mescrollRef" height="1050" @init="mescrollInit" @down="downCallback" @up="upCallback">
			<view class="collage-box">
				<view class="collage-list">
					<view class="collage-item" v-for="(item, index) in tabList" :key="index">
						<view class="collage-detail-left">
							<view class="image-box">
								<image :src="item.has_one_goods['thumb']"></image>
							</view>
							<view class="collage-detail ">
								<view class="detail-name text-line2">{{item.has_one_goods['title']}} </view>
								<view class="detail-price">¥{{item.price}}</view>
							</view>
						</view>
						<view class="detail-right" @click="junit(item.team_id, item.team_member_id)">
							<view class="detail-btn"
								:style="[{'background': item.status == 2 || item.status == 3? '#BFBFBF;': ''}]">
								{{item.status | statusFilter}}
							</view>
							<view v-if="item.status === 1"
								style="display: flex; align-items: center; margin-top: 3upx; text-align: right;">
								<u-line-progress style="height: 10upx; width: 86upx;" active-color="#FF4F10"
									:percent="(item.has_one_team.has_many_success_member_count/ item.has_one_level.member_num) * 100"
									:show-percent="false"></u-line-progress>
								<text style="font-size: 22upx; color: #E5E5E5; margin-left: 16upx;"> <text
										style="color: #FF5E24;">{{item.has_one_team.has_many_success_member_count}}
									</text> /{{item.has_one_level.member_num}}</text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</mescroll-body>
	</view>
</template>

<script>
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";

	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				tabindex: 0,
				orderState: [{
						id: 0,
						title: '全部',
					},
					{
						id: 1,
						title: '拼团中',
					},
					{
						id: 4,
						title: '已拼中',
					},
					{
						id: 2,
						title: '已结束',
					},
					{
						id: 3,
						title: '拼团失败',
					},
				],
				orderPrams: {
					page: 1,
					team_status: ''
				},
				tabList: []
			};

		},
		filters: {
			statusFilter(status) {
				let statusText
				switch (status) {
					case 1:
						statusText = '拼团中'
						break;
					case 2:
						statusText = '未拼中'
						break;
					case 3:
						statusText = '已退款'
						break;
					case 4:
						statusText = '已拼中'
						break;
				}
				return statusText
			}
		},
		onLoad() {
			if (this.$Route.query.type) {
				this.orderState.forEach((el, index) => {
					if (this.$Route.query.type == el.id) {
						this.tabindex = index;
						this.orderPrams = {
							page: 1,
							team_status: el.id
						}
					}
				})
			}

		},
		methods: {
			junit(id, teammemberid){
				this.$Router.push({path: '/pages/index/collage-detail/collage-detail', query: {id: id, teammemberid: teammemberid}})
			},
			onNav(index, id) {
				if (this.tabindex !== index) {
					this.tabindex = index;
					this.orderPrams.team_status = id;
					this.downCallback();
				}
			},
			// 下拉刷新列表
			downCallback() {
				this.mescroll.resetUpScroll(); // 重置列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )

			},
			/*上拉加载的回调*/
			upCallback(page) {
				this.orderPrams.page = page.num;
				this.$http.get('user.groupinglist', this.orderPrams).then(res => {

					let curPageData = res.data.data;
					let curPageLen = curPageData.length;
					let totalCount = res.data.total;
					if (page.num == 1) this.tabList = []; //如果是第一页需手动置空列表
					this.tabList = this.tabList.concat(curPageData); //追加新数据
					this.mescroll.endBySize(curPageLen, totalCount);
				})
				// 获取轮播图数据

			},
		}
	}
</script>

<style lang="scss">
	@import './my-collage.scss';
</style>
